import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';

@Component({
  selector: 'app-click-icon',
  templateUrl: './click-icon.component.html',
  styleUrls: ['./click-icon.component.scss']
})
export class ClickIconComponent implements OnInit {


  @Input() public iconUnClick!: string;
  @Input() public iconClicked?: string;
  @Input() public defaultStatus?: boolean;

  @Output() public iconClick: EventEmitter<boolean> = new EventEmitter<boolean>()

  public status: boolean;
  public currentIcon: string;

  constructor() {
    this.status = false;
    this.currentIcon = '';
  }

  ngOnInit(): void {
    if (this.defaultStatus != undefined) {
      this.status = this.defaultStatus;
    }
    this.currentIcon = this.iconUnClick
    this.changeIcon()
  }

  changeIcon(): void {
    if (this.iconClicked != undefined) {
      this.currentIcon = this.status ? this.iconClicked : this.iconUnClick;
    }
  }

  onClick(): void {
    this.status = !this.status
    this.changeIcon()
    this.iconClick.emit(this.status)
  }
}
